package com.xiaobai.conf;

import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.scrypt.SCryptPasswordEncoder;

/**
 * @author yangdaji
 * @version 1.0 @Description:
 * @date 22-2-12 下午 3:40
 */
// @EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
                .antMatchers("/")
                .permitAll()
                .antMatchers("/home/get1")
                .hasRole("vip1");
        http.rememberMe();
        http.formLogin().successForwardUrl("/home/get1");

        http.logout().logoutSuccessUrl("/home/get2");
    }

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        SCryptPasswordEncoder passwordEncoder = new SCryptPasswordEncoder();
        auth.inMemoryAuthentication()
                .passwordEncoder(passwordEncoder)
                .withUser("root")
                .password(passwordEncoder.encode("root"))
                .roles("vip1");
    }
}
